import { ChannelEnum } from "@/enums/channelEnum";

/**
 * 判断是否是微信环境
 */
export function isWeixin(): boolean {
    let isWexinVal = false;
    // #ifdef H5
    isWexinVal = /MicroMessenger/i.test(navigator.userAgent);
    // #endif

    // #ifdef MP-WEIXIN
    isWexinVal = true;
    // #endif

    return isWexinVal;
}

/**
 * @description 判断是否为安卓环境
 * @return { Boolean }
 */
export function isAndroid() {
    let u = navigator?.userAgent;
    if (u) {
        return u.indexOf("Android") > -1 || u.indexOf("Adr") > -1;
    }
    return uni.getSystemInfoSync().platform === "android";
}

/**
 * @description 判断是否为苹果环境
 * @return { Boolean }
 */
export function isIos() {
    let u = navigator?.userAgent;
    if (u) {
        return u.indexOf("iPhone") > -1 || u.indexOf("iPad") > -1;
    }
    return uni.getSystemInfoSync().platform === "ios";
}

/**
 * 
 * @returns 获取终端参数
 */
export const getAppTerminal = () => {
    if (isAndroid()) {
        return "android";
    } else if (isIos()) {
        return "ios";
    } else {
        return "harmony"; //华为鸿蒙
    }
};

/**
 * 获取渠道值
 * @returns 
 */
export const getChannel = () => {
    let channelValue = null;

    // #ifdef MP-WEIXIN
    channelValue = ChannelEnum.WX_AP;
    // #endif

    // #ifdef H5
    channelValue = isWeixin() ? ChannelEnum.WX_OA : ChannelEnum.H5;
    // #endif

    // #ifdef APP-PLUS
    channelValue = ChannelEnum.APP;
    // #endif

    return channelValue;
};
